/**
 *知识导航界面
 * author:zhangjlt
 * date:2016年8月23日16:30:42
 */
	var competList={
		/**
		 * bindEvent 页面事件
		 */
		bindEvent:function(){
			$("#competlistreturn").unbind().on("click", function () {
                window.location.href = "#industryEquip";
            });
            $(".next-operation").unbind().on("click", function () {
				summer.closeWin();
			});
		},
        /**
         * 绑定路由
         */
        bindRout:function(){
        	//首页
			Path.map("#home").to(function () {
				//记录状态
				common.loadPageDiv("html/index.html",true,true);
			});
			//查询结果列表点解进入页面
			Path.map("#productList/:status").to(function () {
				var type = this.params['status'];
				window.sessionStorage.searchType = type;
				common.loadPageDiv("html/productList.html", true);
			});
			
			//查询结果列表点解进入页面
			Path.map("#industryEquip").to(function () {
				common.loadPageDiv("html/industryEquip.html", true,true);
			});
			
			Path.listen();
        },
		init:function(){
			//初始化set-list-count01高度
			var winHeight = $(window).height();
			$("#set-list-count01").height(winHeight - $(".header").height());
			$("#ulequipList_0").height(winHeight- $("#header").height() - $(".set-list-h1").height() - 10);
			//设备名
			clickTitle = "";
			// 从内存取 设备pk 调用接口
			var pk_industry_charts = window.sessionStorage.pk_industry_chart;
			var pk_industry_chart = pk_industry_charts.split(",")[0];
			var param = {
				"pk_industry_chart":pk_industry_chart
			};
			//调用ajax
			var ajaxUrl = "/industrychar/App/selectindustrychar";
			//转圈提示
	    	common.showLoading();
			common.interfaceAjaxFunction(ajaxUrl,param,this.selectindustrycharSucess);
		},
		selectindustrycharSucess:function(json){
			var _this = this;
	    	//成功时候
	    	if(json.status == "0"){
	    		if(json.data.length > 0){
	    			//把用油点数据显示
	    			competList.showProcessDataList(json);
	    		}else{
	    			//加载设置页面
	    			common.show_nodata("当前设备无用油点信息","set-list-count01");
	    		}
	    	}else{
	    		//给出信息提示
				$("#competlistmainul").height($(window).height() - $(".header").height());
				common.show_error(json.message,"competlistmainul");
	    	}
	    	//转圈提示去除
	    	common.hideLoading();
		},
		showProcessDataList:function(json){
			$("#competlistmainul").html(" ");
			// 从内存中取出设备名
			var pk_industry_chartname =window.sessionStorage.pk_industry_chart.split(",")[1];
			$("#" + window.sessionStorage.currentShownSysPanelId + " .set-list-h1").text(pk_industry_chartname).append("<div class='list-h1-icon'></div>");
			var industryList = json.data;
			var currentindustryRow = industryList;
			//拼接
			var processListStr ="<div><ul class='set_link' id='competListul'> ";
			 //循环显示用油点列表
			for(var j=0;j<currentindustryRow.length;j++){
				var currentProcessRow = currentindustryRow[j];
				if(j==0){
					processListStr += "<li data-code='"+currentProcessRow.pk_industry_chart+"'  data-index='" + j +"' class='processListRow' data-name='"+currentProcessRow.cate_name+"'>" + currentProcessRow.cate_name
								     +"<a href='javascript:void(0);' class='rt_line'></a>"
							         +"<span id='equipList_"  + j + "' class='equipLeftList'></span>"
								     +"</li>";
				}else{
					processListStr += "<li data-code='"+currentProcessRow.pk_industry_chart+"'  data-index='" + j +"' class='processListRow' data-name='"+currentProcessRow.cate_name+"'>" + currentProcessRow.cate_name
						             +"<a href='javascript:void(0);' class='rt_line'></a>"
						             +"<span id='equipList_"  + j + "' class='equipLeftList'></span>"
						             +"</li>";
				}
			}
		    processListStr +="</ul></div>";
			//加到页面上去
			$("#competlistmainul").append(processListStr);
			//事件的绑定加入
			$(".set-list-h1").unbind().on("click",function(){
				var text = $(this).text();
				window.sessionStorage.searchKey = text;
				//标题的显示
				window.sessionStorage.pageTitle = "行业图表";
				//记录跳转之前的页面路由，用于返回
	            var currentURL = window.location.href;
	            window.sessionStorage.productListPageFromRout = currentURL.split("#")[1];
	    		window.location.href = "#productList/industry";
			});
	    	$(".processListRow").unbind().on("click",function(){
	    		$(".processListRow").css("background","#ffffff");
	    		$(this).css("background","#f2f2f2");
	    		//原来的设备列表隐藏
	    		var competIndex = window.sessionStorage.competIndex;
	    		if(competIndex != ""){
	    			$("#equipList_" + competIndex).hide();
	    		}
	    			//取值
	    		var dataCode = $(this).attr("data-code");
	    		var dataIndex = $(this).attr("data-index");
	    		// 点击的设备名
	    		
	    		clickTitle =  $(this).attr("data-name");	
	    		
	    		//记录当前的用油点号
	    		window.sessionStorage.competIndex = dataIndex;
	    		//判断如果为空，则加上对勾
	    		if(dataCode != undefined && dataCode != ""){
	    			//查询用油点
	    			competList.searchEuipByProcessId(dataCode);
	    		}else{
	   				common.showTip("请选择合法的用油点数据");
	    		}
	    	});
	    	
	    	var rightContentPartHeight =  $(".set-list-h1").height() + $(".header").height() + $(".set-list-h2-count").height()+1;
	    	$(".set-list-h1").css("top",$(".header").height());
	    	//$("#competlistmainul").css("top",rightContentPartHeight);
	    	common.initIscrollBody("competlistmainul");
		},
		//查询用油点
		searchEuipByProcessId:function(dataCode){
			//暂时写死
			
				var param = {
						"pk_industry_chart":dataCode
				};
				//调用ajax
				var ajaxUrl = "/compatiblerealtion/App/selectcompatiblerealtion";
				//转圈提示
		    	common.showLoading();
				common.interfaceAjaxFunction(ajaxUrl,param,this.queryEquipmentSucess);
		},
		/**
		 * 查询油品竟品结果处理
		 */
		queryEquipmentSucess:function(json){
			//成功时候
	    	if(json.status == "0"){
	    		if(json.data.compatible.length > 0||json.data.product.length){
	    			//显示油品竟品信息
	    			competList.showQueryEquipment(json);
	    		}else{
	    			//提示当前工序无设备
	    			common.showTip("当前用油点无油品及竞品");
	    			$("#rightCompPart").hide();
	    			common.initIscrollBody("competlistmainul");
	    		}
	    	}else{
	    		//给出信息提示
	    		common.showTip("当前用油点无油品及竞品");
	    	}
	    	//转圈提示去除
	    	common.hideLoading();
		},
		/**
		 * 显示油品竞品信息
		 */
		showQueryEquipment:function(json){
			//工序号取得
			var competIndex = window.sessionStorage.competIndex;
			$("#rightCompPart").show();
			$("#ulequipList_0").html("");
			var equipListStr = "";
			//拼接串
			 equipListStr = '<ul class="set-link-three" style="width:100%;">';
			//循环内层data
			equipListStr += '<li>'+clickTitle+'</li>';
			var jsonData = json.data;
			if(jsonData.product &&jsonData.product.length>0){
				equipListStr += '<li><b>'+'壳牌油品'+'</b></li>';
				for(var i=0;i<jsonData.product.length;i++){
				    var currentEquipRow = jsonData.product[i];
				    equipListStr += '<li datatitle="'+clickTitle+'" title="'+currentEquipRow.product_name+'">'+currentEquipRow.product_name+'</li>';
			    }
			}
			if(jsonData.compatible &&jsonData.compatible.length>0){
				equipListStr += '<li><b>'+'竞品'+'</b></li>';
				for(var i=0;i<jsonData.compatible.length;i++){
				    var currentEquipRow = jsonData.compatible[i];
				    equipListStr += '<li datatitle="'+clickTitle+'"title="'+currentEquipRow.product_name+'">'+currentEquipRow.compatible_product_name+'</li>';
			    }
			}
			equipListStr +='</ul></div>';
			//显示
			$("#ulequipList_0" ).html(equipListStr);
			//动态计算
			var rightContentParttop =  $(".set-list-h1").height() + $(".set-list-h2-count").height();
	    	
	    	$("#rightCompPart").css("top",rightContentParttop);
			var rightContentPartHeight = $(window).height() - $(".set-list-h1").height() - $(".header").height() - $(".set-list-h2-count").height();
			$(".set-link-three").css("min-height",rightContentPartHeight);
			$("#ulequipList_0").css("height",(jsonData.compatible.length +jsonData.product.length+3)* (parseInt($(".set-link-three li").height())+1));
			var rightcompPartHeight = $(window).height() -$(".header").height()-
			$("#rightCompPart").show();
			common.initIscrollBody("rightCompPart");
			//给设备li加上事件绑定
    		$(".set-link-three li").unbind().on("click",function(){
    			var spanHtml = $(this).html();
    			//点油品 竞品标题
    			if (spanHtml == "壳牌油品"||spanHtml == "竞品"||spanHtml == "<b>壳牌油品</b>"||spanHtml == "<b>竞品</b>") {
    				return false
    			}else if (spanHtml == clickTitle) {
    				//点用油点
    				var key = window.sessionStorage.searchKey;
    				key = key +','+clickTitle;
    				window.sessionStorage.searchKey = clickTitle;
    				// window.location.href = "#productList/type1";
    				//标题的显示
    				window.sessionStorage.pageTitle = "行业图表";
    				//记录跳转之前的页面路由，用于返回
    	            var currentURL = window.location.href;
    	            window.sessionStorage.productListPageFromRout = currentURL.split("#")[1];
    	            
    				window.location.href = "#productList/industry";
    			    return false

    			}else{
    				//点油品 竞品
    				var key = window.sessionStorage.searchKey;
    				key = key +','+$(this).attr("datatitle")+','+$(this).html();
    				window.sessionStorage.searchKey = $(this).html();
    				// window.location.href = "#productList/type1";
    				//标题的显示
    				window.sessionStorage.pageTitle = "搜索"; 
    				//记录跳转之前的页面路由，用于返回
    	            var currentURL = window.location.href;
    	            window.sessionStorage.productListPageFromRout = currentURL.split("#")[1];
    				window.location.href = "#productList/searchFromCompetList";
    			    return false
    			}
    			
    		});
		},
	    /**
	     * each page
	     */
	    initialize:function(){
	    	//common.showLoading();
			//common.showTip("设置行业加载成功");
			competList.bindEvent();
			//路由绑定
			competList.bindRout();
			competList.init();
	    }

	};
/*	$(document).ready(function(){
		//common.showLoading();
		//common.showTip("设置行业加载成功");
		competList.bindEvent();
		//路由绑定
		competList.bindRount();
		competList.init();
	});*/
